package kata.chop;

import java.util.Arrays;

public class ArraySlicingBinaryChop extends BinaryChop {

	private int sliceStartPosition;
	private int sliceEndPosition;

	@Override
	protected int chop() {
		computeMiddle();
		if (found())
			return middlePosition;
		if (searchTheLeftHalf()) {
			int[] slice = Arrays.copyOfRange(searchIn, startPosition,
					middlePosition);
			return new ArraySlicingBinaryChop().chop(lookFor, slice);
		}
		if (searchTheRightHalf()) {
			int[] slice = Arrays.copyOfRange(searchIn, middlePosition + 1,
					endPosition + 1);
			return middlePosition
					+ new ArraySlicingBinaryChop().chop(lookFor, slice);
		}
		return NOT_FOUND;
	}
}
